﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Tulde.WindowsPhone.Music.ViewModel;
using Tulde.WindowsPhone.Music;
using System.Windows.Navigation;

namespace MP3tunes.LockerPlayer.UserControls
{
    public partial class AppMenu : UserControl
    {
        public event EventHandler<AppMenuEventArg> OnNavigate;
        private List<NameValuePair<string>> links;
        
        public AppMenu()
        {
            InitializeComponent();
            this.links = new List<NameValuePair<string>>{
              new NameValuePair<string>{
               Name = "Application Settings",
               Value = "/Pages/SettingsManager.xaml"
              },
              new NameValuePair<string>{
               Name = "About",
               Value = "/Pages/About.xaml"
              }
            };

            this.Loaded += new RoutedEventHandler(AppMenu_Loaded);


        }

        void AppMenu_Loaded(object sender, RoutedEventArgs e)
        {
            this.menu.DataContext = this.links;
        }

        private void menu_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            this.menu.SelectionChanged-=new SelectionChangedEventHandler(menu_SelectionChanged);
            
            NameValuePair<string> item = this.menu.SelectedItem as NameValuePair<string>;
            if (this.OnNavigate != null && item != null)
            {
                this.OnNavigate(this, new AppMenuEventArg { Destination = item.Value });
            }
            this.menu.SelectedIndex = -1;
            this.menu.SelectionChanged += new SelectionChangedEventHandler(menu_SelectionChanged);
        }
    }
    public class AppMenuEventArg : EventArgs
    {
        public string Destination { get; set; }
    }
}
